// pages/meau/meau.js
var data = require('../../utils/data')
Page({
    data: {
        activeKey: 0,
        sidenameList:[],
        scroll_height:0,
        drinkList:[],
        typeIndex:"m0",
        tuijianList:"",
        usuallDrink:"",
        babyDrink:"",
        show: false,
        drinksprice:0,
    },
    onLoad(options) {
        this.getsideName()
        this.getALlDrinks()
        this.getMustDrink()
        this.getUsuallDrink()
        this.getBabyDrink()

    },
    onShow(){
        this.getprice()
    },
    showPopup() {
        this.setData({ show: true });
      },
    onClose() {
        this.setData({ show: false });
      },
    getMustDrink(){
        wx.request({
            url: 'http://127.0.0.1:3000/drinks/top',
            method:'GET',
            dataType:'json',
            success:(res)=>{
              console.log("瑞幸必喝",res.data)
              this.setData({
                tuijianList:res.data,
              })
            }
          })
      },
      getUsuallDrink(){
        wx.request({
            url: 'http://127.0.0.1:3000/drinks/topUsuall',
            method:'GET',
            dataType:'json',
            success:(res)=>{
              console.log("我的常点",res.data)
              this.setData({
                usuallDrink:res.data,
              })
            }
          })
      },
      getBabyDrink(){
        wx.request({
            url: 'http://127.0.0.1:3000/drinks/inBaby',
            method:'GET',
            dataType:'json',
            success:(res)=>{
              console.log("保障单品",res.data)
              this.setData({
                babyDrink:res.data,
              })
            }
          })
      },

    getsideName(){
        wx.request({
          url: 'http://127.0.0.1:3000/category',
          method:"GET",
          Type:"json",
          success:(res)=>{
              console.log(res)
              this.setData({
                sidenameList:res.data
              })
          }
        })
    },
    getALlDrinks(){
        wx.request({
            url: 'http://127.0.0.1:3000/drink',
            method:"GET",
            dataType:"json",
            success:(res)=>{
                console.log(res)
                this.setData({
                  drinkList:res.data
                })
            }
          })
    },
    onChange(e){
        console.log(e)
        this.setData({
            typeIndex:'m'+e.detail
        })
    },
     getprice(){
        var list = data.goodList;
        var price=0
        list.forEach(ele=>{
            price =price+ele.nprice
        })
        console.log(price)
        this.setData({
            drinksprice:price*100
        })
    }
})